/*
 * TileUI.fx
 *
 * Created on Mar 26, 2010, 8:53:34 PM
 */

package com.gpsbuddy.objects;

/**
 * @author jonycus
 */
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.Group;

public class TileUI extends CustomNode {

  public-init var zoom;
  public-init var x;
  public-init var y;
  public-init var mapView: MapView;

  public var covering: TileUI[];
  public var zoomParent: TileUI;

  var resource = "http://tile.openstreetmap.org/{zoom}/{x}/{y}.png";

  var image: Image = TileImage {
      url: resource;
      backgroundLoading: true;
    }

  var imageView: ImageView = ImageView {
    image:image
    opacity: .85
  }

  var loading = bind image.progress on replace {
    if (loading ==100) {
      delete this from zoomParent.covering;
    }
  }

  override var visible =  bind ((zoom == mapView.zoom) or (sizeof covering > 0) );

  override protected function create () : Node {
    Group {content: [ imageView]}
  }

}